package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.HospitalStatusBean;

import java.util.List;

/**
 * Created by Administrator on 2017/3/6.
 */

public class PatientStatusAdapter extends RecyclerView.Adapter<PatientStatusAdapter.PatientStatusViewHolder> {
    private List<HospitalStatusBean> list;
    private Context context;
    private LayoutInflater inflater;
    private int itemWidth;
    private onGroupHorizontalClickListener onGroupHorizontalClickListener;

    public void setOnGroupHorizontalClickListener(PatientStatusAdapter.onGroupHorizontalClickListener onGroupHorizontalClickListener) {
        this.onGroupHorizontalClickListener = onGroupHorizontalClickListener;
    }

    public PatientStatusAdapter(List<HospitalStatusBean> list, Context context, int screenWidth) {
        this.list = list;
        this.context = context;
        this.itemWidth = screenWidth / 8;
    }

    public PatientStatusAdapter(List<HospitalStatusBean> list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }


    @Override
    public PatientStatusViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_status_item, null);
        PatientStatusViewHolder patientStatusViewHolder = new PatientStatusViewHolder(view);
        return patientStatusViewHolder;
    }


    @Override
    public void onBindViewHolder(PatientStatusViewHolder holder, final int position) {
        HospitalStatusBean hospitalStatusBean = list.get(position);
        if (hospitalStatusBean.isSelect()) {
            holder.image_status.setImageResource(R.drawable.home_select);
        } else {
            holder.image_status.setImageResource(R.drawable.home_unselect);
        }
        holder.txt_status_name.setText(hospitalStatusBean.getName());
        holder.image_status.setTag(position);
        holder.image_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int index = (int) v.getTag();
                if (onGroupHorizontalClickListener!=null){
                    onGroupHorizontalClickListener.onClick(position);
                }
            }
        });
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public interface onGroupHorizontalClickListener {
        void onClick(int position);
    }
    class PatientStatusViewHolder extends RecyclerView.ViewHolder {
        ImageView image_status;
        TextView txt_status_name;

        public PatientStatusViewHolder(View itemView) {
            super(itemView);
            image_status = (ImageView) itemView.findViewById(R.id.image_status);
            txt_status_name = (TextView) itemView.findViewById(R.id.txt_status_name);
        }
    }
}
